package com.qfhd.soft.cjzcore.Moudle;

import com.qfhd.soft.cjzcore.Core.CJLogger;
import com.qfhd.soft.cjzcore.Model.Task_try_detail_model;
import com.qfhd.soft.cjzcore.Model.Task_try_model;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

public class CJTryPlaceHelper {
    private List<Task_try_model> tryTask_list = new ArrayList<>();
    private Task_try_detail_model detail_model = null;

    private static CJTryPlaceHelper tryPlaceHelper;
    public static CJTryPlaceHelper getInstance(){
        if(tryPlaceHelper == null){
            synchronized (CJTryPlaceHelper.class){
                tryPlaceHelper = new CJTryPlaceHelper();
            }
        }
        return tryPlaceHelper;
    }

    public void setTryTaskList(JSONArray jsonArray) {
        for (int i=0; i<jsonArray.length(); i++){
            try {
                JSONObject obj = jsonArray.getJSONObject(i);
                Task_try_model tmp = Task_try_model.getModelByJSONObject(obj);
                tryTask_list.add(tmp);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        CJLogger.v("tryTask_list size:" + tryTask_list.size());
    }

    public List<Task_try_model> getTryTask_list(){
        return tryTask_list;
    }

    public void changeTaskState(String tid){
        for(Task_try_model item : tryTask_list){
            if(item.tid.equals(tid)){
                item.isGetTask = true;
                break;
            }
        }
    }

    public void setDetailModel(JSONObject object){
        detail_model = Task_try_detail_model.getModelByJSONObject(object);
    }

    public Task_try_detail_model getDetailModel(){
        return detail_model;
    }
}
